package com.zy.pro.shop.web;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zy.core.model.PageView;
import com.zy.core.web.BaseController;
import com.zy.pro.shop.model.Pic;
import com.zy.pro.shop.service.PicService;
import com.zy.pro.shop.web.form.PicSearchForm;
/**
 * 案例图片管理控制器
 *
 */
@Controller
@RequestMapping("/control/shop/picController")
public class PicController extends BaseController {

	private static final Logger logger = Logger.getLogger(PicController.class);
	
	/**
	 * 案例图片管理服务类
	 */
	@Resource(name = "picServiceImpl")
	private PicService picService;
	
	/**
	 * 列出案例图片管理
	 */
	@RequestMapping("/list")
	public String list(PicSearchForm form, ModelMap map) {
		try {
			//设置查询排序
			//TODO eg:form.getOrderby().put("id", "asc");
			
			
			//创建页面对象
			PageView<Pic> pageView = new PageView<Pic>(12, form.getPage());
			form.setFirstResult(pageView.getFirstResult());
			form.setMaxResult(pageView.getMaxresult());
			pageView.setQueryResult(picService.getData(form));
			map.addAttribute("pageView", pageView);
			map.addAttribute("form", form);
			//TODO 转发页面
			return "";
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 显示添加案例图片管理
	 */
	@RequestMapping("/displayAdd")
	public String displayAdd(Pic pic, ModelMap map) {
		try {
			//TODO 加载显示页面数据
			
			
			//TODO 转发页面
			return "";
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 添加案例图片管理
	 */
	@RequestMapping("/add")
	public String add(Pic pic, ModelMap map) {
		try {
			//TODO 设置pic  eg:主键信息
			
			picService.save(pic);
			return list(new PicSearchForm(), map);
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 显示编辑案例图片管理
	 */
	@RequestMapping("/displayEdit")
	public String displayEdit(PicSearchForm form, ModelMap map) {
		try {
			//TODO 查询对象
			//eg:Pic pic = picService.find(form.getId());
			//eg:map.addAttribute("entity", pic);
			
			
			//TODO 转发页面
			return "";
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 编辑案例图片管理
	 */
	@RequestMapping("/edit")
	public String edit(Pic Pic, ModelMap map) {
		try {
			//TODO:处理案例图片管理
			
			
			picService.updateBySelective(Pic);
			return list(new PicSearchForm(), map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
		
	}

	/**
	 * 删除单个案例图片管理
	 */
	@RequestMapping("/deletepic")
	public String delete(PicSearchForm form, ModelMap map) {
		try {
			//TODO  eg:picService.delete(form.getId());
			
			return list(form, map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 批量删除案例图片管理
	 */
	@RequestMapping("/batchDelete")
	public String deletes(PicSearchForm form, ModelMap map) {
		try {
//			TODO  eg:picService.batchDelete(form.getIds());
			
			return list(form, map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
}
